home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 86
/
(Vol 86) My Disc.iso
/
Games
/
pet_1112.swf
/
scripts
/
__Packages
/
com
/
Character.as
next >
Wrap
Text File
|
2009-04-14
|
11KB
|
415 lines
class com.Character extends MovieClip
{
var debugOn = false;
var _isIdle = false;
var _leftEarIsUp = true;
var _rightEarIsUp = false;
var _blueBarks = ["b1","b2","b3","b4"];
var _magentaBarks = ["b1","b2","b3","b4","b5"];
var _magentaBarksSad = ["s1","s2","s3","s4","s5"];
function Character()
{
super();
this.debug("character " + this + " has been initialized");
this.glow = new flash.filters.GlowFilter(16777215,1,3,3,30,3);
this.head = this.head;
this.body = this.body;
this.__set__isMagenta(false);
_global.setTimeout(this,"blink",100);
}
function attachClothes(bodyPart, linkage)
{
this.removeClothes(bodyPart);
switch(bodyPart)
{
case "head":
this.debug("Attaching " + linkage + " to the head");
this.head.gotoAndStop(linkage);
break;
case "eyes":
this.debug("Attaching " + linkage + " to the eyes");
this.head.glasses.gotoAndStop(linkage);
break;
case "neck":
this.debug("Attaching " + linkage + " to the neck");
this.body.neck.gotoAndStop(linkage);
break;
case "body":
this.debug("Attaching " + linkage + " to the body");
this.body.torso.gotoAndStop(linkage);
this.body.arm_r.gotoAndStop(linkage);
this.body.arm_l.gotoAndStop(linkage);
break;
case "legs":
this.debug("Attaching " + linkage + " to the legs");
this.body.torso.pants.gotoAndStop(linkage);
this.body.leg_r.gotoAndStop(linkage);
this.body.leg_l.gotoAndStop(linkage);
break;
default:
trace("Err: bodyPart:String in method attachClothes() must have a value of head, eyes, body, or legs");
}
}
function highlightIcon(bodyPart, glowOn)
{
if(glowOn)
{
this.glow.strength = 30;
}
else
{
this.glow.strength = 0;
}
switch(bodyPart)
{
case "head":
this.head.icon.filters = [this.glow];
break;
case "eyes":
break;
case "neck":
this.body.neck.icon.filters = [this.glow];
break;
case "body":
this.body.torso.icon.filters = [this.glow];
break;
case "legs":
break;
default:
trace("Err: bodyPart:String in method attachClothes() must have a value of head, eyes, body, or legs");
}
}
function removeClothes(bodyPart)
{
switch(bodyPart)
{
case "head":
this.debug("Removing from the head");
this.head.gotoAndStop(1);
break;
case "eyes":
this.debug("Removing from the eyes");
this.head.glasses.gotoAndStop(1);
break;
case "neck":
this.debug("Removing from the neck");
this.body.neck.gotoAndStop(1);
break;
case "body":
this.debug("Removing from the body");
this.body.torso.gotoAndStop(1);
this.body.arm_l.gotoAndStop(1);
this.body.arm_r.gotoAndStop(1);
break;
case "legs":
this.debug("Removing from the legs");
break;
case "all":
this.debug("Stripping clothes!");
this.head.gotoAndStop(1);
this.head.glasses.gotoAndStop(1);
this.body.torso.pants.gotoAndStop(1);
this.body.leg_r.gotoAndStop(1);
this.body.leg_l.gotoAndStop(1);
this.body.neck.gotoAndStop(1);
this.body.torso.gotoAndStop(1);
this.body.arm_l.gotoAndStop(1);
this.body.arm_r.gotoAndStop(1);
break;
default:
trace("Err: bodyPart:String in method removeClothes() must have a value of head, eyes, body, legs, or all");
}
}
function resetEverything()
{
this.__set__isIdle(false);
this.removeClothes("all");
this.armsReset();
this.headReset();
this.earReset();
}
function wave()
{
if(this._armsDown || this.body._currentframe != 2)
{
this.debug("Arms not in resting state. Adding to queue");
this.onArmsUp = function()
{
trace("executing onArmsUp");
this.body.gotoAndPlay("wave");
this.onArmsUp = null;
};
this.body.play();
}
else
{
this.debug("Arms at rest. Animating arms.");
this.body.gotoAndPlay("wave");
}
}
function armsToggle()
{
if(this.body._currentframe != 2)
{
this.onArmsUp = function()
{
this.body.gotoAndPlay("armsDown");
this.onArmsUp = null;
};
this.body.play();
}
else
{
this.body.gotoAndPlay("armsDown");
}
}
function armsReset()
{
if(this.body._currentframe != 2)
{
this.onArmsUp = function()
{
this.body.gotoAndPlay(1);
this.onArmsUp = null;
};
this.body.play();
}
else
{
this.body.gotoAndPlay(1);
}
}
function headTilt(dir)
{
this.moveEar("right");
if(!this.headReset())
{
this.gotoAndPlay(dir + "Tilt");
}
}
function headReset()
{
if(this._currentframe != 1)
{
this.play();
return true;
}
return false;
}
function moveEar(theEar, moveUp)
{
this.debug("Left ear is up? " + this._leftEarIsUp);
this.debug("Right ear is up? " + this._rightEarIsUp);
switch(theEar)
{
case "left":
this.head.ear_l.play();
break;
case "right":
this.head.ear_r.play();
break;
default:
trace("Error. Ear must be a string with value left or right");
}
}
function earReset()
{
if(!this._leftEarIsUp)
{
this.head.ear_l.play();
}
if(this._rightEarIsUp)
{
this.head.ear_r.play();
}
}
function blink(blinkOn)
{
if(blinkOn == undefined)
{
blinkOn = true;
}
clearInterval(this.blinkInterval);
if(blinkOn)
{
var _loc3_ = 3000 + Math.random() * 3000;
if(this._isMagenta)
{
this.head.eyes.gotoAndPlay("magentaBlink");
}
else
{
this.head.eyes.gotoAndPlay("blueBlink");
}
this.blinkInterval = setInterval(this,"blink",_loc3_);
}
}
function look(blinkOn)
{
if(blinkOn == undefined)
{
blinkOn = true;
}
clearInterval(this.lookInterval);
if(blinkOn)
{
var _loc2_ = 3000 + Math.random() * 5000;
this.head.eyes.play();
this.lookInterval = setInterval(this,"look",_loc2_);
}
}
function bark(frameLabel)
{
if(this._isMagenta)
{
this.head.mouth.magenta.gotoAndPlay(frameLabel);
}
else
{
this.head.mouth.blue.gotoAndPlay(frameLabel);
}
}
function barkRandom(isSad)
{
if(isSad == undefined)
{
isSad = false;
}
var _loc2_ = this.calcBark(isSad);
while(_loc2_ == this._prevBark)
{
this.debug("previous bark was " + this._prevBark + "... Recalculating");
_loc2_ = this.calcBark(isSad);
}
if(this._isMagenta)
{
if(!isSad)
{
this.bark(this._magentaBarks[_loc2_]);
}
else
{
this.bark(this._magentaBarksSad[_loc2_]);
}
}
else
{
this.bark(this._blueBarks[_loc2_]);
}
this._prevBark = _loc2_;
}
function calcBark(isSad)
{
var _loc2_ = undefined;
if(this._isMagenta)
{
if(!isSad)
{
_loc2_ = Math.floor(Math.random() * this._magentaBarks.length);
}
else
{
_loc2_ = Math.floor(Math.random() * this._magentaBarksSad.length);
}
}
else
{
_loc2_ = Math.floor(Math.random() * this._blueBarks.length);
}
this.debug("calculating bark: " + _loc2_);
return _loc2_;
}
function idleHead(dir)
{
clearInterval(this.headTiltInterval);
var _loc2_ = Math.random() * 2 >> 0;
var _loc3_ = 5000 + Math.random() * 10000;
if(_loc2_ == 0)
{
this.headTilt("left");
}
else
{
this.headTilt("right");
}
this.headTiltInterval = setInterval(this,"idleHead",_loc3_);
}
function set isIdle(isIdle)
{
this._isIdle = isIdle;
if(!this._isIdle)
{
this.look(false);
clearInterval(this.headTiltInterval);
clearInterval(this.earInterval);
clearInterval(this.armInterval);
}
else
{
this.look();
this.headTiltInterval = setInterval(this,"idleHead",6000,"left");
this.armInterval = setInterval(this,"armsToggle",7000);
}
}
function set isMagenta(val)
{
this.setCharacter(val);
}
function get isMagenta()
{
return this._isMagenta;
}
function setCharacter(isMagenta)
{
this.debug("setting magenta mode to " + isMagenta);
this._isMagenta = isMagenta;
this.head.nose.blue._visible = !isMagenta;
this.head.nose.magenta._visible = isMagenta;
this.head.blue._visible = !isMagenta;
this.head.magenta._visible = isMagenta;
this.head.mouth.blue._visible = !isMagenta;
this.head.mouth.magenta._visible = isMagenta;
if(isMagenta)
{
this.head.eyes.gotoAndPlay("magenta");
}
else
{
this.head.eyes.gotoAndPlay("blue");
}
if(isMagenta)
{
this.head.ear_r.gotoAndStop("magenta");
}
else
{
this.head.ear_r.gotoAndStop("blue");
}
if(isMagenta)
{
this.head.ear_l.gotoAndStop("magenta");
}
else
{
this.head.ear_l.gotoAndStop("blue");
}
this.body.torso.blue._visible = !isMagenta;
this.body.torso.magenta._visible = isMagenta;
this.body.arm_r.blue._visible = !isMagenta;
this.body.arm_r.magenta._visible = isMagenta;
this.body.arm_l.blue._visible = !isMagenta;
this.body.arm_l.magenta._visible = isMagenta;
this.body.leg_r.blue._visible = !isMagenta;
this.body.leg_r.magenta._visible = isMagenta;
this.body.leg_l.blue._visible = !isMagenta;
this.body.leg_l.magenta._visible = isMagenta;
}
function debug(msg)
{
if(this.debugOn)
{
trace(msg);
}
}
}